import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'TextSizeWidget.dart';

class TextWidget extends StatefulWidget {
  final TextEditingController controller; //text 控制器
  final String labelText;
  final String helperText;
  final TextInputType inputType;
  const TextWidget({Key key, this.controller, this.labelText, this.helperText, this.inputType}) : super(key: key);
  @override
  _TextWidgetState createState() => _TextWidgetState();
}

class _TextWidgetState extends State<TextWidget> {
  TextEditingController controller; //text 控制器
  String labelText; //说明
  String helperText; //备注
  TextInputType inputType; //键盘类型
  @override
  void initState() {
    this.controller = widget.controller;
    this.labelText = widget.labelText;
    this.helperText = widget.helperText;
    this.inputType = widget.inputType ?? TextInputType.text;
    // TODO: implement initState
    super.initState();

  }
  @override
  Widget build(BuildContext context) {
    return Container(child:TextFormField(
      controller: controller,
      style: TextStyle(
          fontSize:  ScreenUtil().setSp(25)
      ),
      keyboardType: inputType,
      decoration: InputDecoration(
        labelText: labelText,
        helperText: helperText,
      ),
    ));
  }
}

//打开地图选取页面文本框
class TextOpenMap extends StatefulWidget {
  final TextEditingController controller;
  final String labelText;
  final String helperText;
  final VoidCallback click;
  final VoidCallback btnClick;

  const TextOpenMap({Key key, this.controller, this.labelText, this.helperText, this.click, this.btnClick}) : super(key: key);
  @override
  _TextOpenMapState createState() => _TextOpenMapState();
}

class _TextOpenMapState extends State<TextOpenMap> {
  TextEditingController _controller;
  String labelText;
  String helperText;
  VoidCallback click;
  VoidCallback btnClick;
  @override
  void initState() {
    // TODO: implement initState
    this._controller = widget.controller;
    this.labelText = widget.labelText;
    this.click = widget.click;
    this.btnClick = widget.btnClick;
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Expanded(
          flex: 6,
          child:TextFormField(
            controller: _controller,
            readOnly: true,
            decoration: InputDecoration(
              labelText: labelText,
              helperText: helperText,
            ),
            onTap: click,
            style: TextStyle(
                fontSize:  ScreenUtil().setSp(25)
            ),
          ),
//                    child: TextWidget(
//                      controller:_address,
//                      labelText: "address",
//                      helperText: "请在地图上选取送达地址",
//                    ),
        ),
        Expanded(
            flex: 2,
            child: RaisedButton(
              child: FixedSizeText("常用"),
              onPressed: btnClick,
            )
        )
      ],
    );
  }
}
